package com.zxc.item.controller;

import com.zxc.common.vo.ResultVo;
import com.zxc.item.entity.TbSku;
import com.zxc.item.service.TbSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
public class TbSkuController {

    @Autowired
    private TbSkuService tbSkuService;

    @GetMapping(value = "/sku/list")
    public ResponseEntity<ResultVo<TbSku>> getList(int page,int limit){
        ResultVo<TbSku> list = tbSkuService.getList(page, limit);
        return ResponseEntity.ok(list);
    }

    //http:api.shopping.com/api/item/sku/del/{id}
    @DeleteMapping(value = "/sku/del/{id}")
    public ResponseEntity<Void> delSkuById(@PathVariable("id") long skuId){
         tbSkuService.delSku(skuId);
         return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    //新增商品：http://api.shopping.com/api/item/sku/save
    @PostMapping(value = "/sku/save")
    public ResponseEntity<Void> save(TbSku tbSku){
        tbSkuService.saveSku(tbSku);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //修改商品：http://api.shopping.com/api/item/sku/save
    @PutMapping(value = "/sku/update")
    public ResponseEntity<Void> update(TbSku tbSku){
        tbSkuService.updateSku(tbSku);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
